home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / toc.tex < prev    next >
Encoding:
Text File  |  1992-08-26  |  2.6 KB  |  60 lines

  1. %%%--- Cut here -----------------------------------------------------------
  2. %%% File toc.tex
  3. %
  4. % Automatically generate a Table Of Contents (TOC) while the
  5. % document is being processed by PLAIN TeX
  6. %
  7. % Use \tocref{ texta }{ textb } to insert TOC entries. `texta'
  8. %         will be typeset in the TOC and at the current location,
  9. %         for example `\centerline{\tocref{Chapter 1}{}}' inserts
  10. %         `Chapter 1' at the current location in your document
  11. %         centered, and enters it in the TOC (not centered).
  12. %         `textb' is a prefix text/TeX commands to precede `texta'
  13. %         in the TOC only (it will not appear in the current loc-
  14. %         ation of your document -- {{`textb'`texta'}.....\folio}).
  15. % Use \tocline to add info only intended for the TOC (no page number or
  16. %         dotfill is used for tocline entries).
  17. % Use \tocgen to force the last TOC page to be printed (last command
  18. %         before \end?)
  19. % To specialize, look at the below comments in the right
  20. %
  21. % Uses variable names
  22. %         tocnew, tocopage, tocbox, tocsize, tocstrut, tocref,
  23. %         tocbanner, tocsuffix, tocline, tocstart, tocont, tocgen
  24. %
  25. % Created by Dan Zirin. Copyright (c) 1987 Zar Limited.
  26. % Permission given for inclusion in TeXMaG.
  27. %
  28. \newcount\tocnew\tocnew=1\newcount\tocopage
  29. \newbox\tocbox\newdimen\tocsize
  30. \def\tocstrut{{\vrule height8.5pt depth3.5pt width0pt}} % TOC baselineskip -1pt
  31. \def\tocref#1#2{\tocbanner#1               % Where `texta' is duplicated
  32.     \global\setbox\tocbox=\vbox{
  33.     \box\tocbox\vbox{
  34.     \line{\tocstrut{#2#1}~\dotfill~\folio} % Where the TOC line is made
  35.     }}\tocsuffix}
  36. \def\tocline#1{\tocbanner
  37.     \global\setbox\tocbox=\vbox{
  38.     \box\tocbox\vbox{
  39.     \line{\tocstrut{#1}}
  40.     }}\tocsuffix}
  41. \def\tocbanner{\ifnum\tocnew=1\tocstart\fi
  42.     \ifnum\tocnew=3\tocont\fi}
  43. \def\tocsuffix{\ifdim\tocsize<\ht\tocbox\tocgen
  44.     \global\tocnew=3\fi}
  45. % Do not change tocsize = 1.0 (TeX may go into an infinite loop)
  46. \def\tocstart{\global\tocsize=.95\vsize   % TOC page >95% full, print it
  47.     \global\setbox\tocbox=\vbox{
  48.     \centerline{\tocstrut\bf Table Of Contents} % TOC page 1 banner line 1
  49.     \line{\tocstrut\hfil}                 % TOC page 1 banner line 2 blank line
  50.     }\global\tocnew=2}
  51. \def\tocont{\global\setbox\tocbox=\vbox{
  52.     \centerline{\tocstrut Table Of Contents (Continued)} % TOC page <> 1 banner
  53.     }\global\tocnew=2}
  54. \def\tocgen{\ifnum\tocnew=1
  55.     \message{No TOC entries found.}\else
  56.     \tocopage=\pageno\pageno=0\message{(TOC}
  57.     \shipout\box\tocbox\message{)}
  58.     \pageno=\tocopage\global\tocnew=1\fi}
  59. %%%--- Cut here -----------------------------------------------------------
  60.